package com.candy.demo1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JDBCDemo1 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接对象
        String url="jdbc:mysql://localhost:3306/test1";
        String username = "root";
        String password = "root";
        Connection conn = DriverManager.getConnection(url,username,password);
        String sql = "select * from tb_student";
        PreparedStatement ps = conn.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();

        while (rs.next()){
            System.out.println(rs.getString("tid")+"    "+rs.getString("name"));
        }

        ps.close();
        conn.close();
    }
}
